// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CreateMeshActor.generated.h"
class FMeshDescriptionBuilder;

UCLASS()
class CLASS07_API ACreateMeshActor : public AActor
{
	GENERATED_BODY()
	
public:
	ACreateMeshActor();

	UPROPERTY(VisibleAnywhere)
	UStaticMeshComponent* _mesh;

protected:
	virtual void BeginPlay() override;

	UStaticMesh* CreateMeshData();
	void ChangeTexture(UMaterialInstanceDynamic* mtl);

	struct GlobalData
	{
		FMeshDescriptionBuilder* builder;
		TArray<FVertexID> vertexIDs;
		FPolygonGroupID polygonGroup;
	};

	struct TriangleVertex
	{
		int vertexIndex;
		FVector instanceNormal;
		FVector2D instanceUV;
	};
	void AddTriangleData(GlobalData& globalData, const TriangleVertex& v1,
		                 const TriangleVertex& v2, const TriangleVertex& v3);

public:
	virtual void Tick(float DeltaTime) override;
};
